// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   DMErrorManager.java

package com.iphaeton.lms.course.scorm12.datamodel.cmi;

import com.iphaeton.lms.course.scorm12.DebugIndicator;
import java.io.PrintStream;

// Referenced classes of package com.iphaeton.lms.course.scorm12.datamodel.cmi:
//            CMIRequest

public class DMErrorManager
{

    public DMErrorManager()
    {
        currentErrorCode = "0";
    }

    public void recNotImplementedError(CMIRequest theRequest)
    {
        if(theRequest.isAChildrenRequest())
        {
            if(_Debug)
                System.out.println("Trying to get/set an _children element.\n  This keyword is not permitted to be implemented on the given element");
            SetCurrentErrorCode("401");
        } else
        if(theRequest.isACountRequest())
        {
            if(_Debug)
                System.out.println("Trying to get/set an _count element.\n  This keyword is not permitted to be implemented on the given element");
            SetCurrentErrorCode("401");
        } else
        {
            SetCurrentErrorCode("401");
        }
    }

    public void recKeyWordError(String inElement)
    {
        if(inElement.equals("_children"))
        {
            if(_Debug)
                System.out.println("Trying to set an _children element.  This action is not permitted!");
            SetCurrentErrorCode("402");
        } else
        if(inElement.equals("_count"))
        {
            if(_Debug)
                System.out.println("Trying to set an _count element.  This action is not permitted!");
            SetCurrentErrorCode("402");
        } else
        {
            if(_Debug)
                System.out.println("Trying to set an _version element.  This action is not permitted!");
            SetCurrentErrorCode("402");
        }
    }

    public void recGetKeyWordError(String inElement)
    {
        if(inElement.equals("_children"))
        {
            if(_Debug)
                System.out.println("Trying to get an _children element.  This action is not permitted!");
            SetCurrentErrorCode("202");
        } else
        if(inElement.equals("_count"))
        {
            if(_Debug)
                System.out.println("Trying to get an _count element.  This action is not permitted!");
            SetCurrentErrorCode("203");
        } else
        {
            if(_Debug)
                System.out.println("Trying to get an _version element.  This action is not permitted!");
            SetCurrentErrorCode("401");
        }
    }

    public String GetCurrentErrorCode()
    {
        return currentErrorCode;
    }

    public void SetCurrentErrorCode(String code)
    {
        currentErrorCode = code;
    }

    public void ClearCurrentErrorCode()
    {
        currentErrorCode = errors[0][0];
    }

    public String GetErrorDescription(String code)
    {
        return GetErrorElement(code)[1];
    }

    public String GetErrorDiagnostic(String code)
    {
        return GetErrorElement(code)[2];
    }

    private String[] GetErrorElement(String code)
    {
        for(int i = 0; i < errors.length; i++)
            if(errors[i][0].equalsIgnoreCase(code))
                return errors[i];

        String tmp[] = {
            "", "", ""
        };
        return tmp;
    }

    public boolean isValidErrorCode(String errorCode)
    {
        boolean result = false;
        for(int i = 0; !result && i < errors.length; i++)
            if(errors[i][0].equalsIgnoreCase(errorCode))
                result = true;

        return result;
    }

    private static boolean _Debug;
    private static String currentErrorCode;
    private static String errors[][] = {
        {
            "0", "No Error", "The previous LMS API Function call completed successfully."
        }, {
            "101", "General Exception", "An unspecified, unexpected exception has occurred."
        }, {
            "201", "Invalid argument error", ""
        }, {
            "202", "Element cannot have children", ""
        }, {
            "203", "Element not an array - cannot have count", ""
        }, {
            "301", "Not initialized", "The LMS is not initialized."
        }, {
            "401", "Not implemented error", "The data model element in question was not implemented."
        }, {
            "402", "Invalid set value, element is a keyword", "Trying to set a reserved keyword in the data model.  Trying to set a keyword (_count, _children, or _version).  This is prohibited."
        }, {
            "403", "Element is read only", "Data Element is Read Only (Not Writeable).  Cannot call LMSSetValue() for the element in question."
        }, {
            "404", "Element is write only", "Data Element is Write Only (Not Readable).  Cannot call LMSGetValue() for the element in question."
        }, {
            "405", "Incorrect Data Type", "Invalid Type being used for setting element.  The type being used as the set value argument does not match that of the element being set."
        }
    };

    static 
    {
        _Debug = DebugIndicator.ON;
    }
}
